﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 第三次作业
{
    class Program
    {
        public Shape creatFigure()
        {
            Shape sp = null;
            Random random = new Random();
            int kind = random.Next(3);
            if (kind == 0)
            {
                sp = new Rectangle(10 * random.NextDouble(), 10 * random.NextDouble());
            }
            else if (kind == 1)
            {
                sp = new Square(10 * random.NextDouble());
            }
            else
                sp = new Triangle(10 * random.NextDouble(), 10 * random.NextDouble(), 10 * random.NextDouble());
            return sp;
        }
        static void Main(string[] args)
        {
            double totalArea = 0;
            int i = 0;
            Program program = new Program();
            while(i<10)
            {
                Shape shape = program.creatFigure();
                if(shape.isTrue())
                {
                    if (shape is Rectangle) Console.WriteLine("creat a Rectangle:the area" + shape.getArea());
                    if (shape is Square) Console.WriteLine("creat a Square:the area" + shape.getArea());
                    if (shape is Triangle) Console.WriteLine("creat a Triangle:the area" + shape.getArea());
                }
                i++;
                totalArea += shape.getArea();
            }
            Console.WriteLine("the total area is:" + totalArea);
        }
    }
}
